using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 长方形，由四条线组成
/// </summary>
public class Square : BaseGraph
{
    public Vector3 center;
    public float width;
    public float height;

    public Vector2 Size
    {
        get => new Vector2(width, height);
    }

    public Color color;
    public List<Line> lines;
    
    public override void Draw()
    {
        var offsetW = width / 2f;
        var offsetH = height / 2f;
        Vector3 pos1 = new Vector3(center.x - offsetW, center.y - offsetH, 0);
        Vector3 pos2 = new Vector3(center.x + offsetW, center.y + offsetH, 0);
        Vector3 pos3 = new Vector3(pos1.x, pos2.y, 0);
        Vector3 pos4 = new Vector3(pos2.x, pos1.y, 0);
        
        if (lines == null)
            lines = new List<Line>();
        lines.Clear();
        
        var line = new Line(pos1, pos3);
        line.color = color;
        lines.Add(line);
        line = new Line(pos3, pos2);
        line.color = color;
        lines.Add(line);
        line = new Line(pos2, pos4);
        line.color = color;
        lines.Add(line);
        line = new Line(pos4, pos1);
        line.color = color;
        lines.Add(line);
        
        lines.ForEach(l => l.Draw());
    }
}
